package com.qf.medicaldoctoradmin.user.controller;

import com.qf.common.annotation.NoLoginCheck;
import com.qf.common.common.R;
import com.qf.common.entity.User;

import com.qf.medicaldoctoradmin.user.param.LoginParam;
import com.qf.medicaldoctoradmin.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (User)表控制层
 *
 * @author makejava
 * @since 2024-11-06 20:11:48
 */
@Api(tags = "用户管理")
@RestController
@RequestMapping("/user")
@CrossOrigin
public class UserController {

    @Resource
    private UserService userService;

    /**
     * 登录
     * @param loginParam
     * @return
     */
    @NoLoginCheck
    @ApiOperation(value = "登录", notes = "根据手机号登录")
    @PostMapping("/login")
    public R login(@RequestBody LoginParam loginParam) {
        String token = userService.login(loginParam);
        return R.ok(token);
    }

    /**
     * 注册
     * @param user
     * @return
     */
    @NoLoginCheck
    @ApiOperation(value = "注册", notes = "根据手机号注册")
    @PostMapping("/register")
    public R register(@RequestBody User user) {
        userService.register(user);
        return R.ok("注册成功");
    }

    /**
     * 查询用户信息
     * @return
     */
    @ApiOperation(value = "查询用户信息", notes = "查询用户表全部信息")
    @GetMapping("/list")
    public R getAllUser() {
        List<User> allUser = userService.getAllUser();
        System.out.println(allUser);
        return R.ok("ok");
    }

    /**
     * 短信验证码
     * @param phone
     * @return
     */
    @ApiOperation(value = "短信验证码")
    @NoLoginCheck
    @GetMapping("/code")
    public R sendCode(String phone) {
        userService.sendCode(phone);
        return R.ok("成功");
    }

}

